Even though computers have been shipping with several megabytes of random access memory (RAM) for years now, the total memory available for pre-boot add-in devices is still limited to a mere 1 MB of memory when operating in real mode. This 1 MB limit becomes a burden during pre-boot because there is no standard method for allocating memory from the 640K base memory area. In many cases, the memory allocated by one program will be overwritten by another program because the program either is not aware of the memory allocation method being used or the program has a bug. Nothing prevents one program from overwriting the data of another program in memory because there is no protection scheme during pre-boot. Every program has access to all of the available memory in real mode. Some of the programs competing for the memory are device-specific option-ROMs, the basic input/output system (BIOS), and the operating system (OS) boot loader. There are ways to get past the 1 MB boundary in order to use extended memory, but this typically requires significant changes to a program that was previously written to run in real mode.
When a computer system starts up, the BIOS takes control and the processor executes in real mode. Real mode is typically a 16-bit mode for the processor, but 20-bit addresses can be accessed because of segment addresses. 16-bit mode implies being able to access 16-bit addresses. Segment addressing gives access to 1 MB of memory as opposed to only 64K of memory which would be accessible using only 16-bit addresses with no segments. 1 MB is the total memory space available in real mode. Traditionally the lower 640K of memory is available to applications in real mode. Extended memory, or memory above 1 MB, is not available in real mode.
Referring now to FIG. 1, there is shown a method for using 20-bit segment addresses and offsets to access 1 MB of memory in real mode. The segment register 101 is 16-bits. The offset register 103 is also 16-bits. These registers are combined by shifting the segment register left 4-bits so it is now a 20-bit number 105. The offset register 103 is added to this segment address 105 to generate a 20-bit segment+offset memory reference 107.
A simple way to understand this addressing scheme is to imagine that the segment register 105 always has 4 additional bits on the low order end 109 that cannot be changed. Therefore, the segment register is actually 20 bits, but only 16 are visible outside of the processor. The 16-bit offset 103 is added as follows, according to the example values in FIG. 1. The actual 20-bit Segment Register is
1001 1101 1111 0000 0000
where the bolded bits 0-3 are not visible outside of the processor. The segment register and offset are added as below to generate the physical address in the 1 MB range.
Visible Segment Register:1001 1101 1111 0000 (9DF0h)Real Offset: +0000 0100 0000 0000 (400h)Physical (or linear) address =1001 1110 0011 0000 0000 (9E300h,also written as 9DF0:0400)
A new potential segment starts every 16 bytes in memory. Each segment is 64K long. Thus, segments may overlap each other, i.e., offsets added to a segment address may span more than one segment. There may be over 4000 combinations of segment+offset combinations that will result in an actual address in memory. In other words, each physical address may be within more than one segment.
FIG. 2 illustrates the overlap of 16K segment addresses with segment addresses and 64K offsets. For instance, segment address 0 (201), segment address 1 (203) and segment address 2 (205) are shown. Adding an offset of up to 64K to segment address 0, for example, references memory 207 that overlaps memory referenced using segment address 2 (209). This addressing scheme is well known in the art.
Protected mode enables programs to access more than 1 MB of memory. The processor may switch to protected mode at anytime. The executing software initiates a switch to protected mode. The executing software may also switch back to real mode. This switch to protected mode typically is executed by the boot loader upon loading the operating system (OS) so that all of memory is available to the OS. During protected mode, extended memory can be addressed using a selector and offset combination.
There is a need in the industry to enable pre-boot applications, such as those found on device-specific option-ROMs, to use extended memory in lieu of the lower 1 MB of memory when memory requirements of the application are high. There is also a need for pre-boot applications which have been designed to run in real mode to execute in protected mode without being rewritten.